package com.dizang.ddd.entity;

import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.dizang.ddd.constants.GlobalConstant;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 
 * @author kelvin.cai
 *
 */
@Data
@EqualsAndHashCode(callSuper=false)
public class ParentPomBuilder extends PomBuilder {
    
    public ParentPomBuilder(String artifactId, String parentArtifactId, String groupId,
            List<AbstractProjectBuilder> dependencies, List<AbstractProjectBuilder> modules) {
        super(artifactId, parentArtifactId, groupId, dependencies,modules);
    }
    
    @Override
    public Element buildBaseNode(Document document, Element project) {
        // 不显示内容 name.setNodeValue("不好使");

        String parentArtifactId2 = getParentArtifactId();
        if (parentArtifactId2 != null) {

            Element parent = document.createElement("parent");
            project.appendChild(parent);

            Element groupId = document.createElement("groupId");
            String groupId2 = getGroupId();
            groupId.setTextContent(groupId2);
            parent.appendChild(groupId);

            Element parentArtifactId = document.createElement("artifactId");
            String parentArtifactId3 = getParentArtifactId();
            parentArtifactId.setTextContent(parentArtifactId3);
            parent.appendChild(parentArtifactId);

            Element version = document.createElement("version");
            version.setTextContent(GlobalConstant.version);
            parent.appendChild(version);
        }
        
        Element modelVersion = document.createElement("modelVersion");
        modelVersion.setTextContent(GlobalConstant.modelVersion);
        project.appendChild(modelVersion);
        Element groupId = document.createElement("groupId");
        project.appendChild(groupId);
        groupId.setTextContent(getGroupId());

        Element artifactId = document.createElement("artifactId");
        artifactId.setTextContent(getArtifactId());
        project.appendChild(artifactId);

        Element version = document.createElement("version");
        version.setTextContent(GlobalConstant.version);
        project.appendChild(version);

        Element packaging = document.createElement("packaging");
        packaging.setTextContent("pom");
        project.appendChild(packaging);
        
        return project;

    }
    
    @Override
    public Element buildModuleNode(Document document, Element project) {
        Element modules = document.createElement("modules");
        project.appendChild(modules);
        List<AbstractProjectBuilder> dependencies2 = getModules();
        for (AbstractProjectBuilder abstractProjectCreator : dependencies2) {
            Element service = document.createElement("module");
            service.setTextContent(abstractProjectCreator.getArtifactId());
            modules.appendChild(service);
        }
        return project;

    }
    
    @Override
    public Element buildPropertiesNode(Document document, Element project) {
        Element properties = document.createElement("properties");
        project.appendChild(properties);

        Element springVersion = document.createElement("spring.version");
        springVersion.setTextContent("5.1.0.RELEASE");
        properties.appendChild(springVersion);
        return springVersion;
    }

    @Override
    public Element buildDependenciesNode(Document document, Element project) {
        return project;
    }


}
